package main

import (
	"database/sql"
	"fmt"
	_ "github.com/taosdata/driver-go/v3/taosWS"
	"reflect"
	"strings"
)

type Pcs_Info struct {
	Yx string `json:"yx"`
	Yc string `json:"yc"`
	Yt string `json:"yt"`
	Yk string `json:"yk"`
	BaseDev
}

func (p *Pcs_Info) StructName() string {
	s := reflect.TypeOf(p).Elem().String()
	split := strings.Split(s, ".")
	return (split[len(split)-1])
}

type BaseDev struct {
	DeviceId string `json:"device_id"`
	Tags     string `json:"tags"`
}

//func main() {
//	fmt.Println((&Pcs_Info{}).StructName())
//}

func CreateStable() {

}

func InsertStable() {

}

func main1() {
	var taosDSN = "root:family1@ws(192.168.31.119:6041)/test"
	taos, err := sql.Open("taosWS", taosDSN)
	if err != nil {
		fmt.Println("failed to connect TDengine, err:", err)
		return
	}
	defer taos.Close()
	//taos.Exec("create database if not exists test")
	//taos.Exec("create stable if not exists test.pcsa (ts timestamp, a int) tags(loca binary(64))")
	_, err = taos.Exec("insert into pcs using pcsa tags('yy') values(now,null)")
	if err != nil {
		fmt.Println("failed to insert, err:", err)
		return
	}
	rows, err := taos.Query("select * from test.pcs")
	if err != nil {
		fmt.Println("failed to select from table, err:", err)
		return
	}

	defer rows.Close()
	//for rows.Next() {
	//	var r struct {
	//		ts time.Time
	//		a  int
	//	}
	//	err := rows.Scan(&r.ts, &r.a)
	//	if err != nil {
	//		fmt.Println("scan error:\n", err)
	//		return
	//	}
	//	fmt.Println(r.ts, r.a)
	//}
}
